package com.missilike.core.utils;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.missilike.core.result.BaseResultCode;
import com.missilike.core.result.CommonResult;
import com.missilike.core.result.PageListResult;
import com.missilike.core.result.ResultCode;

/**
 * @author kin
 * @since 2017/12/5
 */
public class ResultUtils {

    public static CommonResult ok() {
        return new CommonResult();
    }

    public static CommonResult ok(Object value) {
        CommonResult result = new CommonResult();
        result.setData(value);
        return result;
    }

    @SuppressWarnings(value = "unchecked")
    public static <T> PageListResult ok(Page<T> page) {
        return (PageListResult<T>) new PageListResult(page);
    }

    public static CommonResult error() {
        return new CommonResult(BaseResultCode.SYSTEM_ERROR);
    }

    public static CommonResult error(ResultCode resultCode) {
        return new CommonResult(resultCode);
    }

    public static CommonResult error(int code, String msg) {
        return new CommonResult(code, msg);
    }
}
